package edu.nf.vrs.app.controller;

import cn.hutool.core.bean.BeanUtil;
import edu.nf.vrs.app.vo.NeedleNumVO;
import edu.nf.vrs.app.vo.ResultVO;
import edu.nf.vrs.search.dto.NeedleNumSearchDTO;
import edu.nf.vrs.search.service.NeedleNumSearchService;
import edu.nf.vrs.vaccination.dto.InoculatePeriodDTO;
import edu.nf.vrs.vaccination.service.NeedleNumService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author: @Wai
 * Date: 2022-4-22
 */

@Tag(name = "NeedleNumController", description = "疫苗服务接口")
@RestController
@RequestMapping("/api/v1")
public class NeedleNumController extends BaseController{

    @DubboReference(interfaceClass = NeedleNumService.class, version = "1.0.0",check = false)
    private NeedleNumService needleNumService;

    @DubboReference(interfaceClass = NeedleNumSearchService.class, version = "1.0.0",check = false)
    private NeedleNumSearchService searchService;

    @GetMapping("/needlenum/search")
    @Operation(summary="根据发放的疫苗针次搜索接种点", method = "GET")
    @Parameter(name = "needleNumVO", description = "接种点检索条件", schema = @Schema(implementation = NeedleNumVO.class))
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "返回接种点信息"),
            @ApiResponse(responseCode = "500", description = "服务异常", content = @Content)
    })
    public ResultVO<List<NeedleNumVO>> searchNeedleNum(NeedleNumVO needleNumVO) {
        NeedleNumSearchDTO dto = BeanUtil.copyProperties(needleNumVO, NeedleNumSearchDTO.class);
        List<NeedleNumSearchDTO> dtoList = searchService.search(dto);
        List<NeedleNumVO> voList = BeanUtil.copyToList(dtoList, NeedleNumVO.class);
        return success(voList);
    }

    @GetMapping("/needlenum/period/{id}")
    @Operation(summary = "根据针次ID查询各个接种时段信息", method = "GET")
    @Parameter(name="needleNumId", description="针次ID", required=true, in = ParameterIn.PATH)
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "返回当前针次的所有接种时段信息"),
            @ApiResponse(responseCode = "500", description = "服务异常", content = @Content)
    })
    public ResultVO<List<InoculatePeriodDTO>> listPeriodByNeedleNumId(@PathVariable("id") Integer needleNumId) {
        List<InoculatePeriodDTO> dtoList = needleNumService.listPeriodByNeedleNumId(needleNumId);
        return success(dtoList);
    }
}

